package com.zzc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzc.common.JsonResult;
import com.zzc.common.TableResult;
import com.zzc.mapper.ApiMappingMapper;
import com.zzc.mapper.RoleMapper;
import com.zzc.pojo.ApiMapping;
import com.zzc.pojo.Role;
import com.zzc.service.ApiMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhouzhicheng
 * @version 1.0  2020/12/29
 */
@Service
public class ApiMappingServiceImpl implements ApiMappingService {
    @Autowired
    private ApiMappingMapper apiMappingMapper;



    @Override
    public TableResult getApiMappingList(String gatewayApiName, Integer state, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        PageInfo<ApiMapping> pageInfo = new PageInfo<>(apiMappingMapper.getApiMappingList(gatewayApiName,state));
        return new TableResult(0,null,Long.valueOf(pageInfo.getTotal()).intValue(), pageInfo.getList());

    }

    @Override
    public JsonResult deleteApiMappingById(Integer[] ids) {
        if (ids == null) {
            return JsonResult.getResultFailed("参数错误！");
        }
        for (Integer id : ids) {
            apiMappingMapper.deleteByPrimaryKey(id);
        }
        return JsonResult.getResultSuccess();
    }

    @Override
    public JsonResult insertApiMapping(ApiMapping apiMapping) {
        if (apiMapping == null) {
            return JsonResult.getResultFailed("参数错误！");
        }
        return apiMappingMapper.insertSelective(apiMapping)>0
                ? JsonResult.getResultSuccess()
                : JsonResult.getResultFailed("添加失败！");
    }

    @Override
    public JsonResult updateByPrimaryKeySelective(ApiMapping apiMapping) {
        if (apiMapping == null) {
            return JsonResult.getResultFailed("参数错误！");
        }
        return apiMappingMapper.updateByPrimaryKeySelective(apiMapping)>0
                ? JsonResult.getResultSuccess()
                : JsonResult.getResultFailed("修改失败！");

    }
}
